﻿using System;
using System.Web.UI;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;
using Wei8808Cms.WebSite.UI;

namespace Wei8808Cms.WebSite.admin.NewType
{
    public partial class EditNewTypeInfoForm : BasicPage
    {
        public int Id;

        private readonly NewTypeBLL _bll = new NewTypeBLL();

        protected void Page_Load(object sender, EventArgs e)
        {
            chkLoginLevel("editNewType");
            if (!int.TryParse(Request.Params["id"] as string, out this.Id))
            {
                JscriptMsg(350, 230, "错误提示", "<b>出现错误啦！</b>您要修改的信息不存在或参数不正确。", "back", "Error");
                return;
            }
            if (!Page.IsPostBack)
            {
                ShowInfo(this.Id);
            }
        }

        private void ShowInfo(int id)
        {
            var model = _bll.GetNewTypeInfo(id);
            txtNewTypeName.Text = model.NewTypeName;
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var model = new NewTypeInfo
                                {
                                    NewTypeId = Id,
                                    NewTypeName = txtNewTypeName.Text.Trim(),
                                    ModifyUser = "李波",
                                    ModifyTime = DateTime.Now,
                                };
                if (_bll.Update(model))
                {
                    JscriptPrint("修改成功！", "NewTypeMasterForm.aspx", "Success");
                }
                else
                {
                    JscriptPrint("修改失败！", "NewTypeMasterForm.aspx", "Error");
                }
            }
            catch (Exception ex)
            {
                JscriptPrint("异常：" + ex.Message, "NewTypeMasterForm.aspx", "Error");
            }
        }
    }
}